/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.components;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext;
import org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent;
import org.eclipse.emf.eef.runtime.impl.utils.EEFConverterUtil;
import org.omg.deployment.DeploymentPackage;
import org.omg.deployment.DeploymentPlan;
import org.omg.deployment.parts.DeploymentPlanPropertiesEditionPart;
import org.omg.deployment.parts.DeploymentViewsRepository;


/**
 * @author Toby McClean; Zeligsoft (2009) Limited
 * @generated
 */
public class DeploymentPlanPropertiesEditionComponent extends SinglePartPropertiesEditingComponent {

	/**
	 * @generated
	 */
	
	public static String BASE_PART = "Base"; //$NON-NLS-1$

	
	
	/**
	 * Default constructor
	 * @generated
	 */
	public DeploymentPlanPropertiesEditionComponent(PropertiesEditingContext editingContext, EObject deploymentPlan, String editing_mode) {
    super(editingContext, deploymentPlan, editing_mode);
    parts = new String[] { BASE_PART };
    repositoryKey = DeploymentViewsRepository.class;
    partKey = DeploymentViewsRepository.DeploymentPlan.class;
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject, 
	 *      org.eclipse.emf.ecore.resource.ResourceSet)
	 * @generated
	 */
	public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
      editingPart.setContext(elt, allResource);
      final DeploymentPlan deploymentPlan = (DeploymentPlan)elt;
      final DeploymentPlanPropertiesEditionPart basePart = (DeploymentPlanPropertiesEditionPart)editingPart;
      // init values
      if (deploymentPlan.getHref() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.href))
        basePart.setHref(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), deploymentPlan.getHref()));
      
      if (deploymentPlan.getId() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.id))
        basePart.setId(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getID(), deploymentPlan.getId()));
      
      if (deploymentPlan.getIdref() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.idref))
        basePart.setIdref(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getIDREF(), deploymentPlan.getIdref()));
      
      if (deploymentPlan.getType() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.type))
        basePart.setType(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getQName(), deploymentPlan.getType()));
      
      if (deploymentPlan.getVersion() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.version))
        basePart.setVersion(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), deploymentPlan.getVersion()));
      
      if (deploymentPlan.getLabel() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.CDPProperties.label))
        basePart.setLabel(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), deploymentPlan.getLabel()));
      
      if (deploymentPlan.getUUID() != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.CDPProperties.uUID))
        basePart.setUUID(EEFConverterUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), deploymentPlan.getUUID()));
      
      if (isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfImplementations)) {
        basePart.setNumOfImplementations(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getELong(), deploymentPlan.getNumImplementation()));
      }
      
      if (isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfinstances)) {
        basePart.setNumOfinstances(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getELong(), deploymentPlan.getNumInstance()));
      }
      
      if (isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConnections)) {
        basePart.setNumOfConnections(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getELong(), deploymentPlan.getNumConnection()));
      }
      
      if (isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfArtifacts)) {
        basePart.setNumOfArtifacts(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getELong(), deploymentPlan.getNumArtifact()));
      }
      
      if (isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConstraints)) {
        basePart.setNumOfConstraints(EEFConverterUtil.convertToString(EcorePackage.eINSTANCE.getELong(), deploymentPlan.getNumLocalityConstraint()));
      }
      
      // init filters
      
      
      
      
      
      
      
      
      
      
      
      
      // init values for referenced views
      
      // init filters for referenced views
      
    }
    setInitializing(false);
  }















	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#associatedFeature(java.lang.Object)
	 */
	public EStructuralFeature associatedFeature(Object editorKey) {
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.XMIProperties.href) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_Href();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.XMIProperties.id) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_Id();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.XMIProperties.idref) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_Idref();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.XMIProperties.type) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_Type();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.XMIProperties.version) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_Version();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.CDPProperties.label) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_Label();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.CDPProperties.uUID) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_UUID();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfImplementations) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_NumImplementation();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfinstances) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_NumInstance();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConnections) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_NumConnection();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfArtifacts) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_NumArtifact();
		}
		if (editorKey == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConstraints) {
			return DeploymentPackage.eINSTANCE.getDeploymentPlan_NumLocalityConstraint();
		}
		return super.associatedFeature(editorKey);
	}

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public void updateSemanticModel(final IPropertiesEditionEvent event) {
    DeploymentPlan deploymentPlan = (DeploymentPlan)semanticObject;
  }

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updatePart(org.eclipse.emf.common.notify.Notification)
	 */
	public void updatePart(Notification msg) {
		if (editingPart.isVisible()) {	
			DeploymentPlanPropertiesEditionPart basePart = (DeploymentPlanPropertiesEditionPart)editingPart;
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_Href().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.href)) {
				if (msg.getNewValue() != null) {
					basePart.setHref(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), msg.getNewValue()));
				} else {
					basePart.setHref("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_Id().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.id)) {
				if (msg.getNewValue() != null) {
					basePart.setId(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getID(), msg.getNewValue()));
				} else {
					basePart.setId("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_Idref().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.idref)) {
				if (msg.getNewValue() != null) {
					basePart.setIdref(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getIDREF(), msg.getNewValue()));
				} else {
					basePart.setIdref("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_Type().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.type)) {
				if (msg.getNewValue() != null) {
					basePart.setType(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getQName(), msg.getNewValue()));
				} else {
					basePart.setType("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_Version().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.XMIProperties.version)) {
				if (msg.getNewValue() != null) {
					basePart.setVersion(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), msg.getNewValue()));
				} else {
					basePart.setVersion("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_Label().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.CDPProperties.label)) {
				if (msg.getNewValue() != null) {
					basePart.setLabel(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), msg.getNewValue()));
				} else {
					basePart.setLabel("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_UUID().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.CDPProperties.uUID)) {
				if (msg.getNewValue() != null) {
					basePart.setUUID(EcoreUtil.convertToString(XMLTypePackage.eINSTANCE.getString(), msg.getNewValue()));
				} else {
					basePart.setUUID("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_NumImplementation().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfImplementations)) {
				if (msg.getNewValue() != null) {
					basePart.setNumOfImplementations(EcoreUtil.convertToString(EcorePackage.eINSTANCE.getELong(), msg.getNewValue()));
				} else {
					basePart.setNumOfImplementations("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_NumInstance().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfinstances)) {
				if (msg.getNewValue() != null) {
					basePart.setNumOfinstances(EcoreUtil.convertToString(EcorePackage.eINSTANCE.getELong(), msg.getNewValue()));
				} else {
					basePart.setNumOfinstances("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_NumConnection().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConnections)) {
				if (msg.getNewValue() != null) {
					basePart.setNumOfConnections(EcoreUtil.convertToString(EcorePackage.eINSTANCE.getELong(), msg.getNewValue()));
				} else {
					basePart.setNumOfConnections("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_NumArtifact().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfArtifacts)) {
				if (msg.getNewValue() != null) {
					basePart.setNumOfArtifacts(EcoreUtil.convertToString(EcorePackage.eINSTANCE.getELong(), msg.getNewValue()));
				} else {
					basePart.setNumOfArtifacts("");
				}
			}
			if (DeploymentPackage.eINSTANCE.getDeploymentPlan_NumLocalityConstraint().equals(msg.getFeature()) && basePart != null && isAccessible(DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConstraints)) {
				if (msg.getNewValue() != null) {
					basePart.setNumOfConstraints(EcoreUtil.convertToString(EcorePackage.eINSTANCE.getELong(), msg.getNewValue()));
				} else {
					basePart.setNumOfConstraints("");
				}
			}
			
		}
	}


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#isRequired(java.lang.Object, int)
	 * @generated
	 */
	public boolean isRequired(Object key, int kind) {
    return key == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfImplementations || key == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfinstances || key == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConnections || key == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfArtifacts || key == DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConstraints;
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public Diagnostic validateValue(IPropertiesEditionEvent event) {
    Diagnostic ret = Diagnostic.OK_INSTANCE;
    if (event.getNewValue() != null) {
      try {
        if (DeploymentViewsRepository.DeploymentPlan.XMIProperties.href == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_Href().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_Href().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.XMIProperties.id == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_Id().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_Id().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.XMIProperties.idref == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_Idref().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_Idref().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.XMIProperties.type == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_Type().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_Type().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.XMIProperties.version == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_Version().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_Version().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.CDPProperties.label == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_Label().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_Label().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.CDPProperties.uUID == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_UUID().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_UUID().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.Statistics.numOfImplementations == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumImplementation().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumImplementation().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.Statistics.numOfinstances == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumInstance().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumInstance().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConnections == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumConnection().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumConnection().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.Statistics.numOfArtifacts == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumArtifact().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumArtifact().getEAttributeType(), newValue);
        }
        if (DeploymentViewsRepository.DeploymentPlan.Statistics.numOfConstraints == event.getAffectedEditor()) {
          Object newValue = event.getNewValue();
          if (newValue instanceof String) {
            newValue = EcoreUtil.createFromString(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumLocalityConstraint().getEAttributeType(), (String)newValue);
          }
          ret = Diagnostician.INSTANCE.validate(DeploymentPackage.eINSTANCE.getDeploymentPlan_NumLocalityConstraint().getEAttributeType(), newValue);
        }
      } catch (IllegalArgumentException iae) {
        ret = BasicDiagnostic.toDiagnostic(iae);
      } catch (WrappedException we) {
        ret = BasicDiagnostic.toDiagnostic(we);
      }
    }
    return ret;
  }

}
